package utils

import (
	"golang.org/x/sys/windows/registry"
	"log"
)

func ReadRegValue(key string) []byte {
	k, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\WDL`, registry.QUERY_VALUE|registry.SET_VALUE)
	if err != nil {
		//log.Fatal(err)
		return nil
	}
	encPublicKey, _, err := k.GetBinaryValue(key)
	if err != nil {
		//log.Fatal(err)
		return nil
	}
	//fmt.Println(enc_public_key,valtype)
	if err := k.Close(); err != nil {
		//log.Fatal(err)
		return nil
	}
	return encPublicKey
}

func WriteRegValue(key string, value []byte) {
	k, _, err := registry.CreateKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\WDL`, registry.QUERY_VALUE|registry.SET_VALUE)
	if err != nil {
		log.Fatal(err)
	}
	if err := k.SetBinaryValue(key, value); err != nil {
		log.Fatal(err)
	}
	if err := k.Close(); err != nil {
		log.Fatal(err)
	}

}
